package com.sure.supermarketserver.sell.adjust;

import com.sure.supermarketserver.common.Result;
import com.sure.supermarketserver.stock.manage.GoodsDto;
import com.sure.supermarketserver.stock.manage.GoodsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: fyf
 * @Date: 2021/07/20/14:23
 * @Description:
 */
@RestController
@RequestMapping("/adjust/manage")
public class AdjustAPI {
    @Resource
    private AdjustService adjustService;

    @GetMapping("page")
    public Result adjustPage(AdjustDto dto){
        Map<String, Object> goodsPage = new HashMap<>();
        try {
            goodsPage = adjustService.goodsPage(dto);
        }catch (Exception e) {
            return Result.fail(Result.ERR_CODE_BUSINESS, e.getMessage());
        }
        return Result.success(goodsPage);
    }

    @PutMapping("")
    public Result adjustUpd(@RequestBody AdjustDto dto) {
        try {
            adjustService.updGoods(dto);
        }catch (Exception e) {
            return Result.fail(Result.ERR_CODE_BUSINESS, e.getMessage());
        }
        return Result.success();
    }
}
